<html>
	<head>
		<meta charset="utf-8">
		<title>倒计时</title>
		<!--以下为css样式-->
		<style type= "text/css">
			.daojishi h2 {
				font-family: Helvetica, Microsoft YaHei, Arial, sans-serif;
				font-size: 14px;
				margin-bottom: 5px;
				color: #151515;
			}
			.daojishi #timer {
				font-family: Helvetica, Microsoft YaHei, Arial, sans-serif;
				font-size: 14px;
				color: #151515;
				font-weight: bold;
			}
		</style>
	</head>
	<body>
		<div class = "daojishi">
			<h2>剩余时间为：</h2>
			<div id = "timer"></div>
		</div>
		<script>
			function timer() {
				var ts = new Date(2015,0, 8, 0, 0, 0) - new Date().valueOf();
				var test = new Date();
				console.log(typeof test)
				//计算剩余的毫秒数
				var dd = parseInt(ts / 1000 / 60 / 60 / 24);
				//计算剩余的天数
				var hh = parseInt(ts / 1000 / 60 / 60 % 24);
				//计算剩余的小时数
				var mm = parseInt(ts / 1000 / 60 % 60);
				//计算剩余的分钟数
				var ss = parseInt(ts / 1000 % 60);
				//计算剩余的秒数
				dd = checkTime(dd);
				hh = checkTime(hh);
				mm = checkTime(mm);
				ss = checkTime(ss);
				document.getElementById("timer").innerHTML = dd + "天" + hh + "时" + mm + "分" + ss + "秒";

			}

			setInterval(timer, 1000);
			function checkTime(i) {
				if (i < 10) {
					i = "0" + i;
				}
				return i;
			}
		</script>
	</body>
</html>
